home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_6.lha / 8_6 / ostream.h < prev    next >
Text File  |  1993-08-08  |  1KB  |  49 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. lass ostream
  6.  
  7. riend istream;
  8.  
  9. streambuf    *bp;
  10. state_value    state;
  11.  
  12. ublic:
  13. ostream& operator<<(const char*);    // write
  14. ostream& operator<<(int a) { return *this<<long(a); }
  15. ostream& operator<<(unsigned a) 
  16.     { return *this<<(unsigned long) a; }
  17. ostream& operator<<(unsigned long);
  18. ostream& operator<<(long);    // beware: << 'a' writes 97
  19. ostream& operator<<(double);
  20. ostream& operator<<(const streambuf&);
  21. ostream& operator<<(const whitespace&);
  22. /    ostream& operator<<(const common&);
  23.  
  24. ostream& put(char);        // put('a') writes a
  25. ostream& flush() { bp->overflow(); return *this; }
  26.  
  27.  
  28.     operator void*(){ return _eof<state?0:this; }
  29. int    operator!()    { return _eof<state; }
  30. int    eof()        { return state&_eof; }
  31. int    fail()        { return _eof<state; }
  32. int    bad()        { return _fail<state; }
  33. int    good()        { return state==_good; }
  34. void    clear(state_value i =0)    { state=i; }
  35. int    rdstate()    { return state; }
  36. /    char*    bufptr()    { return bp->base; }
  37.  
  38. ostream(streambuf* s) { bp = s; state = 0; }
  39. ostream(FILE *fp) { bp = new filebuf(fp); state = 0; }
  40. ostream(int size, char* p)
  41. {
  42.     state = 0;
  43.     bp = new streambuf();
  44.     if (p == 0) p = new char[size];
  45.     bp->setbuf(p, size);
  46. }
  47. ~ostream() { flush(); }
  48. ;
  49.